package net.lab1024.smartadmin.module.business.payment.controller;

import net.lab1024.smartadmin.common.domain.PageResultDTO;
import net.lab1024.smartadmin.common.controller.BaseController;
import net.lab1024.smartadmin.common.domain.ResponseDTO;
import net.lab1024.smartadmin.common.domain.ValidateList;
import net.lab1024.smartadmin.module.business.payment.domain.dto.PaymentAddDTO;
import net.lab1024.smartadmin.module.business.payment.domain.dto.PaymentUpdateDTO;
import net.lab1024.smartadmin.module.business.payment.domain.dto.PaymentQueryDTO;
import net.lab1024.smartadmin.module.business.payment.domain.vo.PaymentVO;
import net.lab1024.smartadmin.module.business.payment.domain.vo.PaymentExcelVO;
import net.lab1024.smartadmin.module.business.payment.service.PaymentService;
import cn.afterturn.easypoi.excel.ExcelExportUtil;
import cn.afterturn.easypoi.excel.entity.ExportParams;
import org.apache.poi.ss.usermodel.Workbook;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * [  ]
 *
 * @author mrmf
 * @version 1.0
 * @company ${company}
 * @copyright (c)  ${company}Inc. All rights reserved.
 * @date 2021-05-24 19:48:52
 * @since JDK1.8
 */
@RestController
@Api(tags = {""})
public class PaymentController extends BaseController {

    @Autowired
    private PaymentService paymentService;

    @ApiOperation(value = "分页查询",notes = "@author mrmf")
    @PostMapping("/payment/page/query")
    public ResponseDTO<PageResultDTO<PaymentVO>> queryByPage(@RequestBody PaymentQueryDTO queryDTO) {
        return paymentService.queryByPage(queryDTO);
    }

    @ApiOperation(value = "添加",notes = "@author mrmf")
    @PostMapping("/payment/add")
    public ResponseDTO<String> add(@RequestBody @Validated PaymentAddDTO addTO){
        return paymentService.add(addTO);
    }

    @ApiOperation(value="修改",notes = "@author mrmf")
    @PostMapping("/payment/update")
    public ResponseDTO<String> update(@RequestBody @Validated PaymentUpdateDTO updateDTO){
        return paymentService.update(updateDTO);
    }

    @ApiOperation(value="批量删除",notes = "@author mrmf")
    @PostMapping("/payment/deleteByIds")
    public ResponseDTO<String> delete(@RequestBody @Validated ValidateList<Long> idList) {
        return paymentService.deleteByIds(idList);
    }

    @ApiOperation(value = "批量导出", notes = "@author mrmf")
    @PostMapping("/payment/export/batch")
    public void batchExport(@RequestBody @Validated ValidateList<Long> idList, HttpServletResponse response) {
        //查询数据
        List<PaymentExcelVO> paymentList = paymentService.queryBatchExportData(idList);
        //导出操作
        ExportParams ex = new ExportParams("", "Sheet1");
        Workbook workbook = ExcelExportUtil.exportExcel(ex, PaymentExcelVO.class, paymentList);
        downloadExcel("", workbook, response);
    }

    @ApiOperation(value = "导出全部", notes = "@author mrmf")
    @PostMapping("/payment/export/all")
    public void exportAll(@RequestBody @Validated PaymentQueryDTO queryDTO, HttpServletResponse response) {
        //查询数据
        List<PaymentExcelVO> paymentList = paymentService.queryAllExportData(queryDTO);
        //导出操作
        ExportParams ex = new ExportParams("", "Sheet1");
        Workbook workbook = ExcelExportUtil.exportExcel(ex, PaymentExcelVO.class, paymentList);
        downloadExcel("", workbook, response);
    }

}
